package com.hongguowei.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.CompareToBuilder;

import javax.persistence.*;
import java.util.List;

@Data
@EqualsAndHashCode
public  class Author implements Comparable<Author>{
    @Id
    private Integer id;
    private String name;
//    @JsonSerialize(using= ToStringSerializer.class)
    private Integer age;
    @OneToMany(targetEntity=Book.class)
    private List<Book> books;

    public Author(Integer id, String name, Integer age, List<Book> books) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.books = books;
    }

    public Author() {

    }


    @Override
    public int compareTo(Author o) {
        return new CompareToBuilder()
                .append(this.age, o.age)
                .append(this.id, o.id)
                .append(this.name, o.name)
                .toComparison();
    }




}